import Vue from 'vue'
import Router from 'vue-router'
import index from '@/components/index'
import cart from '@/components/cart'
import item from '@/components/item'
import detail from '@/components/detail'
import mytest from '@/components/mytest'
import test from '@/components/test'
import register from '@/components/register'
import login from '@/components/login'
import myprofile from '@/components/myprofile'
import myprofiles from '@/components/myprofiles'
import ksprofile from '@/components/ksprofile'
import youpai from '@/components/youpai'
import ksyun from '@/components/ksyun'
import mycarousel from '@/components/mycarousel'
import addgoods from '@/components/addgoods'
import search from '@/components/search'
import allgoods from '@/components/allgoods'
import jian from '@/components/jian'





Vue.use(Router)

var routes = [
        {
          path:'/',
          name:'index',
          component:index
        },
        {
          path:'/cart',
          name:'cart',
          component:cart
        },
        {
          path:'/item',
          name:'item',
          component:item
        },
        {
          path:'/detail',
          name:'detail',
          component:detail
        },
        {
          path:'/mytest',
          name:'mytest',
          component:mytest
        },
        {
          path:'/test',
          name:'test',
          component:test
        },
        {
          path:'/register',
          name:'register',
          component:register
        },
        {
          path:'/login',
          name:'login',
          component:login
        },
        {
          path:'/myprofile',
          name:'myprofile',
          component:myprofile
        },
        {
          path:'/myprofiles',
          name:'myprofiles',
          component:myprofiles,
          beforeEnter:(to,from,next) =>{

            if(localStorage.getItem('username')){
              console.log('已经登录');
              next();
            }else{
              console.log('没有登录');
              next('/login');
            }
          }
        },
          {
          path:'/ksprofile',
          name:'ksprofile',
          component:ksprofile
        },
        {
          path:'/youpai',
          name:'youpai',
          component:youpai
        },
        {
          path:'/ksyun',
          name:'ksyun',
          component:ksyun
        },
        {
          path:'/mycarousel',
          name:'mycarousel',
          component:mycarousel
        },
        {
          path:'/addgoods',
          name:'addgoods',
          component:addgoods
        },
        {
          path:'/search',
          name:'search',
          component:search
        },
          {
          path:'/allgoods',
          name:'allgoods',
          component:allgoods
        },
            {
          path:'/jian',
          name:'jian',
          component:jian
        },
]

export default new Router({
  routes:routes,
  mode:'history'   /*hash*/
})
